package com.huangsm.cloud.consumer.feign.fallback;

import com.huangsm.cloud.consumer.entity.User;
import com.huangsm.cloud.consumer.feign.UserFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * fallbackFactory
 *
 * @author huang
 * @PACKAGE_NAME com.huangsm.cloud.consumer.feign.fallback
 * @PROJECT_NAME microservice-springcloud
 * @date 2019/1/8
 */
@Component
@Slf4j
public class HystrixClientFactroy implements FallbackFactory<UserFeign> {


    @Override
    public UserFeign create(Throwable throwable) {
        log.error("异常信息{}",throwable.getMessage());
        return new UserFeign() {
            @Override
            public User findUser(Long id) {
                User user = new User();
                user.setId(-1L);
                log.info("fallbackFactory调用");
                return user;
            }

            @Override
            public String serviceUrl() {
                return "爆炸了";
            }
        };
    }
}
